"""
自定义异常类
"""
from typing import Optional, Any

class KafkaMonitorException(Exception):
    """Kafka监控工具基础异常"""
    
    def __init__(self, message: str, error_code: Optional[str] = None, details: Optional[Any] = None):
        self.message = message
        self.error_code = error_code
        self.details = details
        super().__init__(self.message)

class KafkaConnectionException(KafkaMonitorException):
    """Kafka连接异常"""
    
    def __init__(self, message: str, bootstrap_servers: Optional[str] = None):
        super().__init__(
            message=message,
            error_code="KAFKA_CONNECTION_ERROR",
            details={"bootstrap_servers": bootstrap_servers}
        )

class KafkaTopicException(KafkaMonitorException):
    """Kafka Topic异常"""
    
    def __init__(self, message: str, topic_name: Optional[str] = None):
        super().__init__(
            message=message,
            error_code="KAFKA_TOPIC_ERROR",
            details={"topic_name": topic_name}
        )

class KafkaMessageException(KafkaMonitorException):
    """Kafka消息异常"""
    
    def __init__(self, message: str, topic: Optional[str] = None, partition: Optional[int] = None):
        super().__init__(
            message=message,
            error_code="KAFKA_MESSAGE_ERROR",
            details={"topic": topic, "partition": partition}
        )

class KafkaAuthenticationException(KafkaMonitorException):
    """Kafka认证异常"""
    
    def __init__(self, message: str, username: Optional[str] = None):
        super().__init__(
            message=message,
            error_code="KAFKA_AUTH_ERROR",
            details={"username": username}
        )

class ValidationException(KafkaMonitorException):
    """参数验证异常"""
    
    def __init__(self, message: str, field: Optional[str] = None, value: Optional[Any] = None):
        super().__init__(
            message=message,
            error_code="VALIDATION_ERROR",
            details={"field": field, "value": value}
        ) 